package com.fernandomdo.ServiceAdministrator;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;


public class MainMenu extends Activity {
	/**
	 * Share some of my variables globally
	 */
	//private static final String TAG = "MainMenu";
	
	Context mContext;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu);
        
        mContext = getApplicationContext();
        
        //Set up the click listeners for the buttons
        ///////////////////////////////////////////////////////////////////////////////////
        findViewById(R.id.list_territories).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainMenu.this, ViewActivity.class);
				intent.putExtra("type", ViewActivity.TERRITORY);
				startActivity(intent);
			}
		});
        
        findViewById(R.id.list_publishers).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MainMenu.this, ViewActivity.class);
				intent.putExtra("type", ViewActivity.PUBLISHER);
	    		startActivity(intent);
			}
		 });
        
        findViewById(R.id.check_in_territory).setOnClickListener(new View.OnClickListener() {
        	@Override
			public void onClick(View v) {
				CheckinDialog checkinDialog = CheckinDialog.newInstance(CheckoutDialog.ADVANCED_DIALOG, null);
				checkinDialog.show(getFragmentManager(), CheckinDialog.CHECKIN);
			}
		});
        
        findViewById(R.id.check_out_territory).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				CheckoutDialog checkoutDialog = CheckoutDialog.newInstance(CheckoutDialog.ADVANCED_DIALOG, null);
				checkoutDialog.show(getFragmentManager(), CheckoutDialog.CHECKOUT);
			}
		});        
    }
    
    ///////////////////////////////////////////////////////////////////////////////////
    // Create the menu
    //////////////////////////////////////////////////////////////////////////////////
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	getMenuInflater().inflate(R.menu.menu_main, menu);
    	return true;
    }
    
    // Respond to the Hidden menu items
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	switch(item.getItemId()) {
    	case R.id.add_territory:
    		startActivity(new Intent(this, AddTerritory.class));
    		return true;
    	case R.id.edit_territory:
    		startActivity(new Intent(this, NotImplemented.class));
    		return true;
    	case R.id.delete_territory:
    		startActivity(new Intent(this, NotImplemented.class));
    		return true;
    	case R.id.import_database:
    		startActivity(new Intent(this, ImportDatabase.class));
    		return true;
    	case R.id.export_database:
    		startActivity(new Intent(this, ExportDatabase.class));
    		return true;
    	case R.id.menu_feedback:
			Intent intent = new Intent(Intent.ACTION_SEND);
			intent.setType("message/rfc822");
			intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"fernandomdo13@gmail.com"});
			intent.putExtra(Intent.EXTRA_SUBJECT,"ServiceAdministrator");
			startActivity(Intent.createChooser(intent, null));
			break;
    	//Add more items here;
    	}
    	return super.onOptionsItemSelected(item);
    }
}